using UnityEngine;
using System.Collections;

public class bug : MonoBehaviour {
	
	public Vector3 target;
	public float timer=0f;
	public GameObject sco;
	public GameObject pum;

	// Use this for initialization
	void Start () {
		
		target = transform.position;
		timer=Random.Range(0f,30f)/10f;
	
	}
	
	// Update is called once per frame
	void Update () {
		
		timer+=Time.deltaTime;
		if(timer>3f)
		{
			timer=Random.Range(0f,30f)/10f;
			target+=new Vector3(Random.Range(-5f,5f)/5,Random.Range(-5f,5f)/5,0f);
		}
		Vector3 vel = (transform.position-target)*Time.deltaTime;
		rigidbody2D.velocity-=new Vector2(vel.x,vel.y);
	
	}

	void OnCollisionEnter2D(Collision2D c)
	{
		if(c.gameObject.tag=="Player")
		{
			GameObject clone=Instantiate(sco,transform.position,transform.rotation)as GameObject;
			Destroy (gameObject);
			
			GameObject clone2=Instantiate(pum,transform.position,transform.rotation)as GameObject;
			Destroy (clone2,3f);
		}
		
	}
}
